package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.ShenglongMonitoringIp;
import com.ruoyi.system.service.IShenglongMonitoringIpService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ip检测Controller
 *
 * @author ruoyi
 * @date 2023-07-01
 */
@Controller
@RequestMapping("/system/ip")
public class ShenglongMonitoringIpController extends BaseController {
    private String prefix = "system/ip";

    @Autowired
    private IShenglongMonitoringIpService shenglongMonitoringIpService;

    @RequiresPermissions("system:ip:view")
    @GetMapping()
    public String ip() {
        return prefix + "/ip";
    }

    /**
     * 查询ip检测列表
     */
    @RequiresPermissions("system:ip:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ShenglongMonitoringIp shenglongMonitoringIp) {
        startPage();
        List<ShenglongMonitoringIp> list = shenglongMonitoringIpService.selectShenglongMonitoringIpList(shenglongMonitoringIp);
        return getDataTable(list);
    }

    /**
     * 导出ip检测列表
     */
    @RequiresPermissions("system:ip:export")
    @Log(title = "ip检测", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShenglongMonitoringIp shenglongMonitoringIp) {
        List<ShenglongMonitoringIp> list = shenglongMonitoringIpService.selectShenglongMonitoringIpList(shenglongMonitoringIp);
        ExcelUtil<ShenglongMonitoringIp> util = new ExcelUtil<ShenglongMonitoringIp>(ShenglongMonitoringIp.class);
        return util.exportExcel(list, "ip检测数据");
    }

    /**
     * 新增ip检测
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存ip检测
     */
    @RequiresPermissions("system:ip:add")
    @Log(title = "ip检测", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ShenglongMonitoringIp shenglongMonitoringIp) {
        return toAjax(shenglongMonitoringIpService.insertShenglongMonitoringIp(shenglongMonitoringIp));
    }

    /**
     * 修改ip检测
     */
    @RequiresPermissions("system:ip:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        ShenglongMonitoringIp shenglongMonitoringIp = shenglongMonitoringIpService.selectShenglongMonitoringIpById(id);
        mmap.put("shenglongMonitoringIp", shenglongMonitoringIp);
        return prefix + "/edit";
    }

    /**
     * 修改保存ip检测
     */
    @RequiresPermissions("system:ip:edit")
    @Log(title = "ip检测", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ShenglongMonitoringIp shenglongMonitoringIp) {
        return toAjax(shenglongMonitoringIpService.updateShenglongMonitoringIp(shenglongMonitoringIp));
    }

    /**
     * 删除ip检测
     */
    @RequiresPermissions("system:ip:remove")
    @Log(title = "ip检测", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(shenglongMonitoringIpService.deleteShenglongMonitoringIpByIds(ids));
    }
}
